package com.fengpanlong.util;

import java.util.ArrayList;
import java.util.List;

import com.fengpanlong.entity.Employee;
import com.fengpanlong.entity.Gogal;
import com.fengpanlong.entity.Task;
import com.fengpanlong.service.GogalService;

public class GogalHelp {
	private Gogal gogal;
	private String gogalId;
	private List<TaskHelp> taskHelpList;
	private int rate = 0;
	
	public class TaskHelp {
		private Task task;
		private Employee employee;
		public Task getTask() {
			return task;
		}
		public Employee getEmployee() {
			return employee;
		}
	}
	
	public GogalHelp(String gogalId){
		this.gogalId = gogalId;
		this.gogal = GogalService.findGogalByGogalId(gogalId);
		taskHelpList = new ArrayList<GogalHelp.TaskHelp>();
		TaskHelp taskHelp = null;
		List<Task> taskList = GogalService.findTasksByGogalId(gogalId);
		for(Task task : taskList) {
			taskHelp = new TaskHelp();
			taskHelp.task = task;
			taskHelp.employee = GogalService.findEmployeeByTaskId(task.getId());
			taskHelpList.add(taskHelp);
			rate +=task.getRate();
		}
		if(taskList.size() != 0) {
			rate = rate / taskList.size();
		}
	}
	
	public List<TaskHelp> getTaskHelpList() {
		return taskHelpList;
	}
	public String getGogalId() {
		return gogalId;
	}
	public Gogal getGogal() {
		return gogal;
	}
	public int getRate() {
		return rate;
	}
}
